#include <iostream>
#include <regex>

#define MATCH(r, v)                                                                                    \
    std::cout << matchCount++ << ". '\033[31m" r "\033[0m' match '\033[32m" v "\033[0m':" << std::endl; \
    match(std::regex{r}, std::string{v})

namespace {
int matchCount = 0;

void match(std::regex &&regex, std::string &&value)
{
    std::smatch result;
    bool retval = std::regex_match(value, result, regex);
    std::cout << "    retval: \033[33m" << std::boolalpha << retval << "\033[0m" << std::endl;
    if (retval) {
        for (int i = 0; i < result.size(); i++) {
            std::cout << "    group[" << i << "]: '" << result[i] << "'" << std::endl;
        }
    }
    std::cout << std::endl;
}
} // namespace

int main()
{
    MATCH("([0-9]+(\\.[0-9]+)?)", "1.2");
    MATCH("([0-9]+(\\.[0-9]+)?)", "1");
    MATCH("([0-9]+(\\.[0-9]+)?)", "1.");
    MATCH("([0-9]+(\\.[0-9]+)?)", ".");
    MATCH("([0-9]+(\\.[0-9]+)?)", "a");
    MATCH("([0-9]+(\\.[0-9]+)?)(px|%)?", "1.2");
    MATCH("([0-9]+(\\.[0-9]+)?)(px|%)?", "1.2px");
    MATCH("([0-9]+(\\.[0-9]+)?)(px|%)?", "1.2%");
    MATCH("([0-9]+(\\.[0-9]+)?)(px|%)?", "1.");
    MATCH("([0-9]+(\\.[0-9]+)?)(px|%)?", "1");
    MATCH("([0-9]+(\\.[0-9]+)?)(px|%)?", "a");
    MATCH("([0-9]+(\\.[0-9]+)?)(px|%)?", "#");
    return 0;
}
